package com.lgt_enterprise_android.view.pages.b.staff;

import android.os.Bundle;
import android.widget.TextView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lgt_enterprise_android.R;
import com.lgt_enterprise_android.base.BaseActivity;
import com.lgt_enterprise_android.utils.BasicHttp;
import com.lgt_enterprise_android.utils.CommonUtil;
import com.lgt_enterprise_android.utils.HttpManager;

public class StaffDetailActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_staff_detail);

        String staffID=getIntent().getStringExtra("staff_id");

        HttpManager.getStaffDetail(mContext, staffID, new BasicHttp.IMyCallBack() {
            @Override
            public void onResponse(Object resonseObj) {
                JSONObject jo=(JSONObject)resonseObj;

                JSONObject JOWorkerDO=jo.getJSONObject("workerDTO");

                setText(R.id.txt_name,JOWorkerDO.getString("name"));
                setText(R.id.txt_age,JOWorkerDO.getString("age"));
                setText(R.id.txt_gender, CommonUtil.getGenderStr(JOWorkerDO.getIntValue("gender")));

                JSONArray jsonArraySkillDO=jo.getJSONArray("workerTagDOList");
                String goodAT="";
                for(int i=0;i<jsonArraySkillDO.size();i++){
                    JSONObject joSkill=jsonArraySkillDO.getJSONObject(i);
                    goodAT+=joSkill.getString("tagContent")+",";
                }
                if(goodAT.length()>0){
                    goodAT=goodAT.substring(0,goodAT.length()-1);
                }
                setText(R.id.txt_skill,goodAT);
                setText(R.id.txt_mobile,JOWorkerDO.getString("phoneNumber"));


                JSONArray jsonArray=jo.getJSONArray("workerExpectAddressDOList");

                String address="";
                for(int i=0;i<jsonArray.size();i++){
                    address+=jsonArray.getJSONObject(i).getString("address")+",";
                }


                if (address.length() > 0) {
                    address = address.substring(0, address.length() - 1);
                }

                setText(R.id.txt_expect_address,address);
            }

            @Override
            public void onFailure(String mes) {

            }
        });
    }

    private void setText(int viewId,String txt){
        ((TextView)findViewById(viewId)).setText(txt);
    }
}
